package com.example.wangzhenyu;

import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.read.R;
import com.example.wangzhenyu.adapter.ChapterAdapter;

public class wangzhenyuMainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private ChapterAdapter adapter;
    private MainViewModel viewModel;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new ChapterAdapter(chapter -> {
            // Navigate to DetailActivity
            DetailActivity.start(this, chapter.getDetailid());
        });
        recyclerView.setAdapter(adapter);

        viewModel = new ViewModelProvider(this).get(MainViewModel.class);
        viewModel.getChapters("b56758b8f0fcbcc3").observe(this, chapters -> {
            adapter.setChapters(chapters);
        });
    }
}